package com.xiehospital.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xiehospital.common.annotation.Log;
import com.xiehospital.common.core.controller.BaseController;
import com.xiehospital.common.core.domain.AjaxResult;
import com.xiehospital.common.enums.BusinessType;
import com.xiehospital.common.core.domain.entity.SysReserve;
import com.xiehospital.system.service.ISysReserveService;
import com.xiehospital.common.utils.poi.ExcelUtil;
import com.xiehospital.common.core.page.TableDataInfo;

/**
 * 预约信息
 *
 * @author xierujian
 */
@RestController
@RequestMapping("/system/reserve")
public class SysReserveController extends BaseController
{
    @Autowired
    private ISysReserveService sysReserveService;

    /**
     * 查询预约信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:reserve:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysReserve sysReserve)
    {
        startPage();
        List<SysReserve> list = sysReserveService.selectSysReserveList(sysReserve);
        return getDataTable(list);
    }

    /**
     * 导出预约信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:reserve:export')")
    @Log(title = "预约信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysReserve sysReserve)
    {
        List<SysReserve> list = sysReserveService.selectSysReserveList(sysReserve);
        ExcelUtil<SysReserve> util = new ExcelUtil<SysReserve>(SysReserve.class);
        util.exportExcel(response, list, "预约信息数据");
    }

    /**
     * 获取预约信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:reserve:query')")
    @GetMapping(value = "/{reserveId}")
    public AjaxResult getInfo(@PathVariable("reserveId") Long reserveId)
    {
        return success(sysReserveService.selectSysReserveByReserveId(reserveId));
    }

    /**
     * 新增预约信息
     */
    @PreAuthorize("@ss.hasPermi('system:reserve:add')")
    @Log(title = "预约信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysReserve sysReserve)
    {
        return toAjax(sysReserveService.insertSysReserve(sysReserve));
    }

    /**
     * 修改预约信息
     */
    @PreAuthorize("@ss.hasPermi('system:reserve:edit')")
    @Log(title = "预约信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysReserve sysReserve)
    {
        return toAjax(sysReserveService.updateSysReserve(sysReserve));
    }

//    /**
//     * 删除预约信息
//     */
//    @PreAuthorize("@ss.hasPermi('system:reserve:remove')")
//    @Log(title = "预约信息", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{reserveIds}")
//    public AjaxResult remove(@PathVariable Long[] reserveIds)
//    {
//        return toAjax(sysReserveService.deleteSysReserveByReserveIds(reserveIds));
//    }
    /**
     * 删除预约信息
     */
    @PreAuthorize("@ss.hasPermi('system:reserve:remove')")
    @Log(title = "预约信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{reserveId}")
    public AjaxResult remove(@PathVariable Long reserveId)
    {
        return toAjax(sysReserveService.deleteSysReserveByReserveId(reserveId));
    }

    /**
     * 预约确认入住
     */
    @PreAuthorize("@ss.hasPermi('system:reserve:checkInBed')")
    @Log(title = "预约信息", businessType = BusinessType.UPDATE)
    @PutMapping("/checkInBed")
    public AjaxResult checkInBed(@RequestBody SysReserve sysReserve)
    {
        return toAjax(sysReserveService.checkInSysBed(sysReserve));
    }
}
